import api from './_api';
import tool from './../tool/tool.js'

/*global $*/
const actions = {
  fetchData () {
    return api.getCourses()
    // return Promise.resolve('abc')
  },

  setProgramList ({commit}, programList) {
    commit('SETPROGRAMLIST', programList)
  },

  setCurrProgram ({commit}, currPprogram) {
    commit('SETPROGRAM', currPprogram)
  },

  setCurrWorkout ({commit}, currWorkout) {
    commit('SETCURRWORKOUT', currWorkout)
  },

  setNewWorkouts ({commit}, newWorkouts) {
    commit('SETNEWWORKOUTS', newWorkouts)
  },

  setYearMonth ({commit}, yearMonth) {
    commit('SETYEARMONTH', yearMonth)
  },

  setSelectedDate ({commit}, selectedDate) {
    commit('SETSELECTEDDATE', selectedDate)
  },

  getCourses ({commit}) {
    // api.getCourses()
    //   .then(res => {
    //     commit('INITIALIZATION', res);
    //   })

    // let res = api.getCourses();
    // let courseList = [];

    // if(res.length) {
    //   res.forEach(item => {
    //     let course = {};
    //     $.extend(course, item, {workouts: []})
    //     course.workouts = constructWorkouts(item.workouts);
    //     courseList.push(course);
    //   })
    // }
    // commit('INITIALIZATION', courseList);
  }
}


export default actions
